// Tags:
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <vector>

const int N = 1e2 + 5;
int n;
char num[N], ans[N];
std::vector<int> four, seven;

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("number.in", "r", stdin);
  freopen("number.out", "w", stdout);
#endif
#endif

  while (scanf("%s", num) != EOF) {
    n = strlen(num);
    if (n & 1) {
      ++n;
      for (int i = 0; i < (n >> 1); ++i) { putchar('4'); }
      for (int i = 0; i < (n >> 1); ++i) { putchar('7'); }
      putchar('\n');
      continue;
    }
    four.clear(), seven.clear();
    bool sev = true;
    for (int i = 0, x; i < n; ++i) {
      x = num[i] - '0';
      if (x < 4) {
        sev = false;
        int f = four.size(), s = seven.size();
        if (std::abs(f - s) <= n - i) {
          for (int j = 0; j < i; ++j) putchar(ans[j]);
          for (int j = 1; j <= (n >> 1) - f; ++j) putchar('4');
          for (int j = 1; j <= (n >> 1) - s; ++j) putchar('7');
        } else {
          if (f > s) {
            // int j = 0;
            // for (; j < four[f - ((n >> 1) - (n - i) - s)]; ++j) {
            //   putchar(ans[j]);
            // }
            // while (j++ < n) putchar('7');
          } else {
            // int l = 0, r = four.size(), mid;
            // while (l < r) {
            //   mid = (l + r) >> 1;
            //   if (i - 1 - four[mid] - (f - mid - 1) <= (n >> 1) - i - f)
            //     r = mid;
            //   else
            //     l = mid + 1;
            // }
            // int j = 0;
            // for (; j < four[r]; ++j) { putchar(ans[j]); }
            // while (j++ < n) putchar('4');
          }
        }
        break;
      } else if (x == 4) {
        sev = false;
        ans[i] = '4';
        four.push_back(i);
      } else if (x < 7) {
        sev = false;
        seven.push_back(i);
        ans[i] = '7';
        ++i;
        int f = four.size(), s = seven.size();
        if (std::abs(f - s) <= n - i) {
          for (int j = 0; j < i; ++j) putchar(ans[j]);
          for (int j = 1; j <= (n >> 1) - f; ++j) putchar('4');
          for (int j = 1; j <= (n >> 1) - s; ++j) putchar('7');
        } else {
          if (f > s) {
            // int j = 0;
            // for (; j < four[f - ((n >> 1) - (n - i) - s)]; ++j) {
            //   putchar(ans[j]);
            // }
            // while (j++ < n) putchar('7');
          } else {
            // int l = 0, r = four.size(), mid;
            // while (l < r) {
            //   mid = (l + r) >> 1;
            //   if (i - 1 - four[mid] - (f - mid - 1) <= (n >> 1) - i - f)
            //     r = mid;
            //   else
            //     l = mid + 1;
            // }
            // int j = 0;
            // for (; j < four[r]; ++j) { putchar(ans[j]); }
            // while (j++ < n) putchar('4');
          }
        }
        break;
      } else if (x == 7) {
        ans[i] = '7';
        seven.push_back(i);
      } else if (sev) {
        n += 2;
        for (int i = 0; i < (n >> 1); ++i) { putchar('4'); }
        for (int i = 0; i < (n >> 1); ++i) { putchar('7'); }
        break;
      } else {
        // while ((seven.end()-1) != ) seven.pop_back();
        // std::lower_bound(seven.begin(), seven.end(), four.back());
        // four.pop_back();
        ans[i] = '7';
        seven.push_back(i);
      }
    }
    putchar('\n');
  }
  return 0;
}